﻿//1.0 加载JqueryDatabase
jQuery(function ($) {
    var oTable1 = $('#sample-table-2').dataTable({
        "aoColumns": [
          { "bSortable": false },
          { "bSortable": true },
          { "bSortable": false },
          { "bSortable": false },
          
          { "bSortable": false },
           { "bSortable": false },
          { "bSortable": false },
          { "bSortable": false },
          { "bSortable": false },
          { "bSortable": true },
        
          { "bSortable": false },

        ],
        oLanguage: {
            "sProcessing": "正在加载中......",
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "对不起，查询不到相关数据！",
            "sEmptyTable": "表中无数据存在！",
            "sInfo": "当前显示： _START_ 到 _END_ 条，共 _TOTAL_ 条",
            "sInfoFiltered": "数据表中共为 _MAX_ 条记录",
            "sSearch": "",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上一页",
                "sNext": "下一页",
                "sLast": "末页"
            }
        },
        iDisplayLength: 10,
        bLengthChange: false
    });


    $('table th input:checkbox').on('click', function () {
        var that = this;
        $(this).closest('table').find('tr > td:first-child input:checkbox')
        .each(function () {
            this.checked = that.checked;
            $(this).closest('tr').toggleClass('selected');
        });

    });


    $('[data-rel="tooltip"]').tooltip({ placement: tooltip_placement });
    function tooltip_placement(context, source) {
        var $source = $(source);
        var $parent = $source.closest('table')
        var off1 = $parent.offset();
        var w1 = $parent.width();

        var off2 = $source.offset();
        var w2 = $source.width();

        if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
        return 'left';
    }




})
//点击删除小图标操作


window.onload = function () {
    //省市级联
    new PCAS("province", "city", "area");

    //2.0 页面初始化
   
    $("td").addClass("tdBorder");

    //2.2 table表头上的样式
    $("#sample-table-2>thead tr>th").attr("style", "font-weight:bold;color:black;text-align:center");


    //2.3 table搜索样式
    $("#sample-table-2_filter label input").attr("placeholder", "搜索(多条件搜索中间用空格隔开)").attr("style", "width:50%");
    $("#sample-table-2_filter label").attr("style", "width:100%");
    $("#sample-table-2_filter").attr("style", "margin-right: -16px;");
    $("#sample-table-2_wrapper .row").first().children().eq(1).attr("style", "margin-top:-12px");
    $("#sample-table-2_wrapper").attr("style", "margin-top:-32px");

    //2.4 增加表单行间距样式
    $("div .modal-body .row:not(#iconr)").attr("style", "margin-top:7px;");
    $("div .modal-body .row .col-sm-3").attr("style", "margin-top:6px;text-align:right");
    $("div#myModal .modal-body .row i:lt(6)").attr("style", "margin-top:9px;text-align:right;");


    //2.5 时间
    $.mask.definitions['~'] = '[+-]';
    $('.input-mask-date').mask('9999-99-99');
    //下拉列表选择框
    $("#SupAgent").select2();

    //2.6 按钮样式
    $("button.btn.btn-sm:gt(0)").attr("style", "margin:-5px 0px 0px 4px");
    $("#butadd").attr("style", "margin-top:-4px");

    //2.7 显示页数一行的样式
    $("#sample-table-2").next().find(".col-sm-6").eq(0).attr("style", "margin-left: -12px;margin-top: 5px;");
    $("#sample-table-2").next().find(".col-sm-6").eq(1).attr("style", "margin-left: 12px;margin-top: 0px;");


    //验证审核权限
    $.ajax({
        url: "PowerOfVertify",
        dataType: "Json",
        data: {},
        Type: "Post",
        success: function (data) {
            var json = eval(data);
            if (json.result == "Success") {
                $(".btnverity").removeAttr("style");
                
            }
            else {
                $(".btnverity a").removeAttr("style");
                $(".btnverity").unbind("click");
                $(".btnverity a").attr("style", "color:gray;cursor:not-allowed;");

            }
        }
    });

    //3.0   功能
    //3.1   删除


    //3.2   刷新
    $("#buflush").click(function () {
        history.go(0);
    });

    //5.2   点击新增按钮
    //5.2.1 初始化新增
    function initForm() {
        PCAS("province", "city", "area");
        $("#Province").val("").removeAttr("style");
        $("#City").val("");
        $("#Country").val("");

        $("#SupAgent").select2("val", "");
        $("#s2id_SupAgent").attr("style", "width:100%;height:34px;border: 1px solid #d5d5d5;");
        $(".select2-choice").attr("style","height:32px;background-color: #fff;border:0;");
        $(".icon-lightbulb").attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
        $("div#myModal .modal-body .row input:not([autocomplete])").val("").removeAttr("style");
        //$("div#myModal .modal-body .row select:lt(1)").val("0").removeAttr("style");
        $("#Description").val("").removeAttr("style");
        $("#DicValue").val("100");
        var myDate = new Date();
        $("#BeginTime").val(myDate.getFullYear() + "-" + (myDate.getMonth()+1 )+ "-" + myDate.getDate());
        $("#EndTime").val((myDate.getFullYear()+1) + "-" + (myDate.getMonth()+1) + "-" + myDate.getDate());

        $("#but_saveadd").removeAttr("style");
        $("#but_savemodify").removeAttr("style").attr("style", "display:none");

        $("#LookPWD").attr("class", "btn btn-minier btn-white icon-eye-open");
        $("#UserPassword").attr("type", "password");

    }
    //5.2.2 点击新增按钮，初始化模态窗口
    $("#butadd").click(function () {
        initForm();
        $("#myModal").modal();
    });
    //5.2.3 验证表单
    $("#AgentName").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#AgentName").blur(function () {
        var reg = /^[\u4e00-\u9fa5_a-zA-Z0-9]{2,12}$/;  //长度为2-12的汉英文数字下滑线
        var obj = $(this).val();
        if (!reg.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });



    $("#LegalName").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#LegalName").blur(function () {
        var reg = /^[\u4e00-\u9fa5_a-zA-Z0-9]{2,5}$/;  //长度为2-5的汉英文数字下滑线
        var obj = $(this).val();
        if (!reg.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });

    $("#Mobile").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#Mobile").blur(function () {
        var reg = /^1[358]\d{9}$/;
        var reg170 = /^170\d{8}$/;//手机验证
        var obj = $(this).val();
        if (!reg.test(obj) && !reg170.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });


    $("#UserPassword").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#UserPassword").blur(function () {
        var reg = /^\w{6,15}$/;
        var obj = $(this).val();
        if (!reg.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });

    $("#Province").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#Province").blur(function () {

        if ($("#Province").val() == "") {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });

    $("#UserAccount").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#UserAccount").blur(function () {
        var reg = /^[a-zA-Z_][a-zA-Z0-9_]{2,16}$/;
        var obj = $(this).val();
        if (!reg.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });


    //5.3  新增保存
    $("#but_saveadd").click(function () {
        var AgentName = $("#AgentName").val();
        var DicValue = $("#DicValue").val();
        var SupAgent = $("#SupAgent").val();
        var Mobile = $("#Mobile").val();
        var Province = $("#Province").val();
        var City = $("#City").val();
        var Country = $("#Country").val();
        var LegalName = $("#LegalName").val();
        var BeginTime = $("#BeginTime").val();
        var EndTime = $("#EndTime").val();
        var UserPassword = $("#UserPassword").val();
        var UserAccount = $("#UserAccount").val();
        var Description = $("#Description").val();
        var flag = true;
        var msg = "";
        if (1 == 1) {
            var reg = /^[\u4e00-\u9fa5_a-zA-Z0-9]{2,12}$/;  //长度为2-12的汉英文数字下滑线
            if (!reg.test(AgentName)) {
                flag = false;
                $("#AgentName").attr("style", " border-color: red;");
                $("#AgentName").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "代理名称填写错误（长度为2-12的汉英文数字下滑线）";
            }
        }

        if ($("#SupAgent").val() == null && flag) {

            $("#SupAgent").attr("style", " border-color: red;");
            $("#SupAgent").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
            msg = "请选择上级代理商";
            flag = false;
        }
        
        if ($("#Province").val() == "" && flag) {

            $("#Province").attr("style", " border-color: red;");
            $("#Province").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
            msg = "请选择代理地区";
            flag = false;
        }

        

        if (1 == 1 && flag) {
            var reg = /^([\u4e00-\u9fa5]+|([a-z]+\s?)+)$/;
            if (!reg.test(LegalName)) {
                flag = false;
                $("#LegalName").attr("style", " border-color: red;");
                $("#LegalName").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "法人姓名填写错误";
            }
        }

        if (1 == 1 && flag) {
            var reg = /^\w{6,15}$/;
            if (!reg.test(UserPassword)) {
                flag = false;
                $("#UserPassword").attr("style", " border-color: red;");
                $("#UserPassword").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "密码填写错误（长度为6-15个字符）";
            }
        }

        if (1 == 1 && flag) {
            var reg = /^1[358]\d{9}$/;
            var reg170 = /^170\d{8}$/; 
            if (!reg.test(Mobile) && !reg170.test(Mobile)) {
                flag = false;
                $("#Mobile").attr("style", " border-color: red;");
                $("#Mobile").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "请填写正确的手机号";

            }
        }

       

        if (1 == 1 && flag) {
            var reg = /^[a-zA-Z_][a-zA-Z0-9_]{2,16}$/;
            if (!reg.test(UserAccount)) {
                flag = false;
                $("#UserAccount").attr("style", " border-color: red;");
                $("#UserAccount").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "登录帐号帐号填写错误（3-17位字符开头，后加字符下划线）";
            }
        }
        if (!flag) {
            $.gritter.add({
                title: '消息提醒',
                text: msg,
                class_name: 'gritter-info gritter-center'
            });
            return;
        }



        $.ajax({
            url: "AddNewAgent",
            dataType: "json",
            Type: "POST",
            data: {
                AgentName: AgentName,
                Mobile: Mobile,
                SupAgent:SupAgent,
                Province: Province,
                City: City,
                Country: Country,
                DicValue: DicValue,
                LegalName: LegalName,
                BeginTime: BeginTime,
                EndTime: EndTime,
                UserPassword: UserPassword,
                UserAccount: UserAccount,
                Description: Description
            },
            success: function (data) {
                var json = eval(data);
                if (json.result == "Success") {
                    $("#but_infoclose").click();
                    $.gritter.add({
                        title: '消息提醒',
                        text: json.message,
                        class_name: 'gritter-info gritter-center'
                    });

                    history.go(0);
                }
                else {
                    $.gritter.add({
                        title: '消息提醒',
                        text: json.message,
                        class_name: 'gritter-info gritter-center'
                    });
                }
            }
        });
    });

    //5.4  修改
    //5.41 修改初始化
    //$(".toModify").click(function () {
    //    var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    //    initForm();
    //    $.ajax({
    //        url: "LoadAgentModify",
    //        datatype: "json",
    //        type: "post",
    //        data: {
    //            id: id
    //        },
    //        success: function (data) {
    //            var json = eval(data);
    //            $("#idHidden").val(json.AgentID);
    //            $("#AgentName").val(json.AgentName);
    //            $("#DicValue").val(json.AgentLevel);
    //            $("#Mobile").val(json.Mobile);
    //            $("#SupAgent").select2("val", json.ParentAgentID);
    //            new PCAS("province", "city", "area", json.Province, json.City, json.Country)
    //            $("#LegalName").val(json.LegalName);
    //            $("#BeginTime").val(json.BeginTime1);
    //            $("#EndTime").val(json.EndTime1);
    //            $("#UserAccount").val(json.UserAccount);
    //            $("#Description").val(json.Description);
    //            $("#UserPassword").val(json.UserPassword);
    //            $("#but_saveadd").attr("style", "display:none");
    //            $("#but_savemodify").removeAttr("style");
    //            $("#myModal").modal();
    //        }

    //    });
    //});
    //5.42 保存修改
    $("#but_savemodify").click(function () {
        var AgentID = $("#idHidden").val();
        var AgentName = $("#AgentName").val();
        var AgentLevel = $("#DicValue").val();
        var Mobile = $("#Mobile").val();
        var ParentAgentID = $("#SupAgent").val();
        var UserPassword = $("#UserPassword").val();
        var Province = $("#Province").val();
        var LegalName = $("#LegalName").val();
        var City = $("#City").val();
        var Country = $("#Country").val();
        var BeginTime = $("#BeginTime").val();
        var EndTime = $("#EndTime").val();
        var Description = $("#Description").val();
        var UserAccount = $("#UserAccount").val();

        var flag = true;
        var msg = "";
        if (1 == 1) {
            var reg = /^[\u4e00-\u9fa5_a-zA-Z0-9]{2,12}$/;  //长度为2-12的汉英文数字下滑线
            if (!reg.test(AgentName)) {
                flag = false;
                $("#AgentName").attr("style", " border-color: red;");
                $("#AgentName").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "代理名称填写错误（长度为2-12的汉英文数字下滑线）";
            }
        }


        if ($("#Province").val() == "" && flag) {

            $("#Province").attr("style", " border-color: red;");
            $("#Province").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
            msg = "请选择代理地区";
            flag = false;
        }

        if (1 == 1 && flag) {
            var reg = /^([\u4e00-\u9fa5]+|([a-z]+\s?)+)$/;
            if (!reg.test(LegalName)) {
                flag = false;
                $("#LegalName").attr("style", " border-color: red;");
                $("#LegalName").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "法人姓名填写错误。";
            }
        }

        if (1 == 1 && flag) {
            var reg = /^\w{6,15}$/;
            if (!reg.test(UserPassword)) {
                flag = false;
                $("#UserPassword").attr("style", " border-color: red;");
                $("#UserPassword").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "密码填写错误（长度为6-15个字符）";
            }
        }

        if (1 == 1 && flag) {
            var reg = /^1[358]\d{9}$/;
            var reg170 = /^170\d{8}$/;
            if (!reg.test(Mobile) && !reg170.test(Mobile)) {
                flag = false;
                $("#Mobile").attr("style", " border-color: red;");
                $("#Mobile").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "请填写正确的手机号";

            }
        }



        if (1 == 1 && flag) {
            var reg = /^[a-zA-Z_][a-zA-Z0-9_]{2,16}$/;
            if (!reg.test(UserAccount)) {
                flag = false;
                $("#UserAccount").attr("style", " border-color: red;");
                $("#UserAccount").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "登录帐号填写错误（2-16位字符下划线）";
            }
        }
        if (!flag) {
            $.gritter.add({
                title: '消息提醒',
                text: msg,
                class_name: 'gritter-info gritter-center'
            });
            return;
        }
        $.ajax({
            url: "SaveModifyAgent",
            dataType: "json",
            Type: "POST",
            data: {
                id: AgentID,
                AgentName: AgentName,
                Mobile: Mobile,
                ParentAgentID: ParentAgentID,
                AgentLevel: AgentLevel,
                UserPassword: UserPassword,
                BeginTime: BeginTime,
                Province: Province,
                LegalName:LegalName,
                City: City,
                Country: Country,
                EndTime: EndTime,
                UserAccount: UserAccount,
                Description: Description
            },
            success: function (data) {
                var json = eval(data);
                if (json.result == "Success") {
                    $("#but_infoclose").click();
                    $.gritter.add({
                        title: '消息提醒',
                        text: json.message,
                        class_name: 'gritter-info gritter-center'
                    });
                    history.go();
                }
                else {
                    $.gritter.add({
                        title: '消息提醒',
                        text: json.message,
                        class_name: 'gritter-info gritter-center'
                    });
                }
            }
        });
    });
    //5.5  点击查看密码按钮
    $("#LookPWD").click(function () {
        if ($(this).hasClass("icon-eye-close")) {
            $(this).removeClass("icon-eye-close").addClass("icon-eye-open");
            $("#UserPassword").attr("type", "password");
            $("#UserPassword1").attr("type", "password");
        }
        else {
            $(this).removeClass("icon-eye-open").addClass("icon-eye-close");
            $("#UserPassword").attr("type", "text");
            $("#UserPassword1").attr("type", "text");
        }
    });
    ////5.6 审核
    //$(".btnverity").click(function () {

    //    var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    //    if (!confirm("确定审核通过（通过后该用户将可以登录使用）")) { return; }
    //    $.ajax({
    //        url: "VertifyAgent",
    //        dataType: "json",
    //        Type: "POST",
    //        data: {
    //            id: id
    //        },
    //        success: function (data) {
    //            var json = eval(data);
    //            if (json.result == "Success") {
    //                $("#but_infoclose").click();
    //                $.gritter.add({
    //                    title: '消息提醒',
    //                    text: json.message,
    //                    class_name: 'gritter-info gritter-center'
    //                });

    //                history.go();
    //            }
    //            else {
    //                $.gritter.add({
    //                    title: '消息提醒',
    //                    text: json.message,
    //                    class_name: 'gritter-info gritter-center'
    //                });
    //            }
    //        }


    //    });
    //});
    
    //    //5.7 停止

    //    $(".btnstop").click(function () {

    //        var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    //            if (!confirm("确定停止使用（停用后该用户将不能登录使用）")) { return; }
    //            $.ajax({
    //                url: "StopAgent",
    //                dataType: "json",
    //                Type: "POST",
    //                data: {
    //                    id: id
    //                },
    //                success: function (data) {
    //                    var json = eval(data);
    //                    if (json.result == "Success") {
    //                        $("#but_infoclose").click();
    //                        $.gritter.add({
    //                            title: '消息提醒',
    //                            text: json.message,
    //                            class_name: 'gritter-info gritter-center'
    //                        });

    //                        history.go();
    //                    }
    //                    else {
    //                        $.gritter.add({
    //                            title: '消息提醒',
    //                            text: json.message,
    //                            class_name: 'gritter-info gritter-center'
    //                        });
    //                    }
    //                }
    //            });
            
    //    });

    //    //5.8 生效
    //    $(".btnactive").click(function () {

    //        var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    //            if (!confirm("确定生效该项（生效后该用户重新可以登录使用）")) { return; }
    //            $.ajax({
    //                url: "ActiveAgent",
    //                dataType: "json",
    //                Type: "POST",
    //                data: {
    //                    id: id
    //                },
    //                success: function (data) {
    //                    var json = eval(data);
    //                    if (json.result == "Success") {
    //                        $("#but_infoclose").click();
    //                        $.gritter.add({
    //                            title: '消息提醒',
    //                            text: json.message,
    //                            class_name: 'gritter-info gritter-center'
    //                        });

    //                        history.go();
    //                    }
    //                    else {
    //                        $.gritter.add({
    //                            title: '消息提醒',
    //                            text: json.message,
    //                            class_name: 'gritter-info gritter-center'
    //                        });
    //                    }
    //                }
    //            });
            
    //    });

    //    //5.9 注销         
    //    $(".btnunreg").click(function () {
    //        var id = $(this).parent().parent().parent().parent().children().eq(1).text();
           
    //            if (!confirm("确定注销该项（注销后将删除该用户）")) { return; }
    //            $.ajax({
    //                url: "UnregAgent",
    //                dataType: "json",
    //                Type: "POST",
    //                data: {
    //                    id: id
    //                },
    //                success: function (data) {
    //                    var json = eval(data);
    //                    if (json.result == "Success") {
    //                        $("#but_infoclose").click();
    //                        $.gritter.add({
    //                            title: '消息提醒',
    //                            text: json.message,
    //                            class_name: 'gritter-info gritter-center'
    //                        });

    //                        history.go();
    //                    }
    //                    else {
    //                        $.gritter.add({
    //                            title: '消息提醒',
    //                            text: json.message,
    //                            class_name: 'gritter-info gritter-center'
    //                        });
    //                    }
    //                }
    //            });
            
    //    });
    //存量明细

        //$(".btnDetail").click(function () {
        //    var id = $(this).parent().parent().parent().parent().children().eq(1).text();
        //    window.window.location.href = "../BillStorehouse/BillInfo?id="+id+"&productID=";

        //});

    $("#bgdiv").attr("style", "display:none");
}
//存量明细
function btnDetailClick(id) {
   
    window.window.location.href = "../BillStorehouse/BillInfo?id=" + id + "&productID=";
}
function initForm() {
    PCAS("province", "city", "area");
    $("#Province").val("").removeAttr("style");
    $("#City").val("");
    $("#Country").val("");

    $("#SupAgent").select2("val", "");
    $("#s2id_SupAgent").attr("style", "width:100%;height:34px;border: 1px solid #d5d5d5;");
    $(".select2-choice").attr("style", "height:32px;background-color: #fff;border:0;");
    $(".icon-lightbulb").attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    $("div#myModal .modal-body .row input:not([autocomplete])").val("").removeAttr("style");
    //$("div#myModal .modal-body .row select:lt(1)").val("0").removeAttr("style");
    $("#Description").val("").removeAttr("style");
    $("#DicValue").val("100");
    var myDate = new Date();
    $("#BeginTime").val(myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate());
    $("#EndTime").val((myDate.getFullYear() + 1) + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate());

    $("#but_saveadd").removeAttr("style");
    $("#but_savemodify").removeAttr("style").attr("style", "display:none");

    $("#LookPWD").attr("class", "btn btn-minier btn-white icon-eye-open");
    $("#UserPassword").attr("type", "password");

}
//修改
function btnmodifyClick(id) {

    initForm();
    $.ajax({
        url: "LoadAgentModify",
        datatype: "json",
        type: "post",
        data: {
            id: id
        },
        success: function (data) {
            var json = eval(data);
            $("#idHidden").val(json.AgentID);
            $("#AgentName").val(json.AgentName);
            $("#DicValue").val(json.AgentLevel);
            $("#Mobile").val(json.Mobile);
            $("#SupAgent").select2("val", json.ParentAgentID);
            new PCAS("province", "city", "area", json.Province, json.City, json.Country)
            $("#LegalName").val(json.LegalName);
            $("#BeginTime").val(json.BeginTime1);
            $("#EndTime").val(json.EndTime1);
            $("#UserAccount").val(json.UserAccount);
            $("#Description").val(json.Description);
            $("#UserPassword").val(json.UserPassword);
            $("#but_saveadd").attr("style", "display:none");
            $("#but_savemodify").removeAttr("style");
            $("#myModal").modal();
        }

    });
}
//停止
function btnstopClick(id) {

    if (!confirm("确定停止使用（停用后该用户将不能登录使用）")) { return; }
    $.ajax({
        url: "StopAgent",
        dataType: "json",
        Type: "POST",
        data: {
            id: id
        },
        success: function (data) {
            var json = eval(data);
            if (json.result == "Success") {
                $("#but_infoclose").click();
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });

                history.go();
            }
            else {
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });
            }
        }
    });
}
//注销
function btnunregClick(id) {

    if (!confirm("确定注销该项（注销后将删除该用户）")) { return; }
    $.ajax({
        url: "UnregAgent",
        dataType: "json",
        Type: "POST",
        data: {
            id: id
        },
        success: function (data) {
            var json = eval(data);
            if (json.result == "Success") {
                $("#but_infoclose").click();
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });

                history.go();
            }
            else {
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });
            }
        }
    });
}
//生效
function btnactiveClick(id) {
    if (!confirm("确定生效该项（生效后该用户重新可以登录使用）")) { return; }
    $.ajax({
        url: "ActiveAgent",
        dataType: "json",
        Type: "POST",
        data: {
            id: id
        },
        success: function (data) {
            var json = eval(data);
            if (json.result == "Success") {
                $("#but_infoclose").click();
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });

                history.go();
            }
            else {
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });
            }
        }
    });

}
//审核
//function btnverityClick(id) {
//    if (!confirm("确定审核通过（通过后该用户将可以登录使用）")) { return; }
//    $.ajax({
//        url: "VertifyAgent",
//        dataType: "json",
//        Type: "POST",
//        data: {
//            id: id
//        },
//        success: function (data) {
//            var json = eval(data);
//            if (json.result == "Success") {
//                $("#but_infoclose").click();
//                $.gritter.add({
//                    title: '消息提醒',
//                    text: json.message,
//                    class_name: 'gritter-info gritter-center'
//                });

//                history.go();
//            }
//            else {
//                $.gritter.add({
//                    title: '消息提醒',
//                    text: json.message,
//                    class_name: 'gritter-info gritter-center'
//                });
//            }
//        }


//    });
    
//}
$(".btnverity").click(function () {

    var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    if (!confirm("确定审核通过（通过后该用户将可以登录使用）")) { return; }
    $.ajax({
        url: "VertifyAgent",
        dataType: "json",
        Type: "POST",
        data: {
            id: id
        },
        success: function (data) {
            var json = eval(data);
            if (json.result == "Success") {
                $("#but_infoclose").click();
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });

                history.go();
            }
            else {
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });
            }
        }


    });
});